package com.eorchis.module.department.service.impl;

import com.eorchis.core.basedao.condition.BaseTreeCondition;
import com.eorchis.core.servicetemplate.treetemplate.DndTreeTemplate;
import com.eorchis.core.servicetemplate.treetemplate.jsonbean.JsonTreeBean;
import com.eorchis.module.department.domain.Department;
import com.eorchis.module.department.domain.DepartmentTreeCondition;
import com.eorchis.module.department.domain.Department;
import com.eorchis.module.department.manager.IDepartmentTreeManager;
import com.eorchis.module.department.service.IDepartmentTreeService;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

@Service("com.eorchis.module.department.service.impl.DepartmentTreeServiceImpl")
public class DepartmentTreeServiceImpl extends DndTreeTemplate implements IDepartmentTreeService {

	@Autowired
	@Qualifier("com.eorchis.module.department.manager.impl.DepartmentTreeManagerImpl")
	private IDepartmentTreeManager departmentTreeSyncManager;

	public void doDndProcess(BaseTreeCondition condition) throws Exception {
		dndProcess(condition);
	}

	public List<JsonTreeBean> doProcess(BaseTreeCondition condition) throws Exception {
		return process(condition);
	}

	protected void updateTreeParentID(BaseTreeCondition condition) throws Exception {
		this.departmentTreeSyncManager.updateTreeParentID(condition);
	}

	protected void updateTreeOrderNum(BaseTreeCondition condition) throws Exception {
		this.departmentTreeSyncManager.updateTreeOrderNum(condition);
	}

	protected List<?> findNextNodeList(BaseTreeCondition condition) throws Exception {
		return this.departmentTreeSyncManager.listDepartmentTree((DepartmentTreeCondition) condition);
	}

	protected boolean isLeapNode(BaseTreeCondition condition) throws Exception {
		if (condition.getBasebean() != null) {
			condition.setBasebean(null);
		}
		return this.departmentTreeSyncManager.isLeapNode((DepartmentTreeCondition) condition);
	}

	protected List<JsonTreeBean> objListToJsonList(List<?> treeNodeList) throws Exception {
		List<JsonTreeBean> resultList = new ArrayList<JsonTreeBean>();
		for (Iterator<?> i$ = treeNodeList.iterator(); i$.hasNext();) {
			Object obj = i$.next();
			Department department = (Department) obj;
			JsonTreeBean jtBean = new JsonTreeBean();
			jtBean.setId(department.getDeptID().toString());
			jtBean.setText(department.getDeptName());
			resultList.add(jtBean);
		}
		return resultList;
	}

	public Department getDepartment(DepartmentTreeCondition condition) throws Exception {
		return this.departmentTreeSyncManager.getDepartment(condition);
	}
	
}